/**
 * Created With IntelliJ IDEA
 * Description:leetcode：26. 删除有序数组中的重复项
 * <a href="https://leetcode.cn/problems/remove-duplicates-from-sorted-array/">...</a>
 * User: DELL
 * Data: 2022-12-08
 * Time: 22:30
 */


public class Solution {
    public int removeDuplicates(int[] nums) {
        //判空处理
        if (nums.length == 0) {
            return 0;
        }
        int newLen = 0; //去重后数组的长度
        int len = nums.length;
        for (int i = 0; i < len; i++) {
            if (i != len-1 && nums[i] == nums[i+1]) {
                continue;
            }
            nums[newLen++] = nums[i];
        }
        return newLen;
    }
}
